<?php

namespace Api\Controller;
use Think\Controller;
class ChangyanController extends Controller {
	//获取用户信息
    public function userinfo() {
		
        if($_SESSION['user']){
			$key="3b39b00cec76c90507ba552701006178";
			if(strstr($_SESSION['user']['avatar'],"http://")){
				 $imgUrl=$_SESSION['user']['avatar'];
			}else{
				$imgUrl='http://www.wen-world.com/data/upload/avatar/'.$_SESSION['user']['avatar'];
			}
			
			$nickname=$_SESSION['user']['user_nicename'];
			$profileUrl="http://www.wen-world.com/user/index/index/id/".$_SESSION['user']['id'].".html";
			$isvUserId=$_SESSION['user']['id'];
			
            $toSign = "img_url=".$imgUrl."&nickname=".$nickname."&profile_url=".$profileUrl."&user_id=".$isvUserId;
            $signature = base64_encode(hash_hmac("sha1", $toSign, $key, true));
			$_SESSION['user']['sign']=$signature;
        
            $ret=array(  
				"is_login"=>1, //已登录，返回登录的用户信息
				"user"=>array(
					"user_id"=>$_SESSION['user']['id'],
					"nickname"=>$_SESSION['user']['user_nicename'],
					"img_url"=>$imgUrl,
					"profile_url"=>$profileUrl,
					"sign"=>$signature
            ));
        

        }else{
            $ret=array("is_login"=>0);//未登录
        }
        
        echo $_GET['callback'].'('.json_encode($ret).')';
        

    }
	
	//退出登录
	public function logout() {
			if($_SESSION['user']){
				session("user",null);
				$return=array(
				'code'=>1,
				'reload_page'=>1
				);
			}else{
				$return=array(
				'code'=>1,
				'reload_page'=>0
				);
			}
	
	
    
	}
	//数据回推
	public function pinglun() {
		if($_POST){
			$info=$_POST['data'];
			$info=json_decode($info,true);
			FQ('data11',$info);
			$data['url']=$info['url'];
			$data['email']=$info['comments'][0]['ip'];
			$data['uid']=$info['comments'][0]['user']['userid'];
			$data['createtime']=date('Y-m-d H:i:s',time());
			$data['content']=$info['comments'][0]['content'];
			$data['full_name']=$info['comments'][0]['user']['nickname'];
			$data['post_id']=$info['comments'][0]['referid'];//评论ID
			$data['parentid']=$info['comments'][0]['replyid'];//回复的评论ID，没有为0
			M('comments')->add($data); 
			
		}else{
			echo "页面错误";
			$data=array ( 'comments' => array ( 0 => array ( 'apptype' => 0, 'attachment' => array ( ), 'channelid' => 974076, 'channeltype' => 1, 'cmtid' => '1016112558', 'content' => '[/钱]', 'ctime' => 1462341352000, 'from' => 0, 'ip' => '114.216.94.30', 'opcount' => 0, 'referid' => '1016112558', 'replyid' => '1016110621', 'spcount' => 0, 'user' => array ( 'nickname' => '意琦行', 'sohuPlusId' => 388166532, 'usericon' => '/data/upload/avatar/57298a38b3d63.jpg', 'userid' => '7', 'userurl' => '/user/index/index/id/7.html', ), 'useragent' => 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36', ), ), 'metadata' => '{"ChangY_ImgTag":"YES","local_ip":"10.16.43.162","ChangY_Img":"http://0d077ef9e74d8.cdn.sohucs.com/topic_picture_1213614731_1462340657072"}', 'title' => '文交所头条-邮币卡为什么需要“托管” 又如何鉴定?_文天下', 'ttime' => 1462268019000, 'url' => 'http://www.wen-world.com/article/1285.html', );
			
			$map=array ( 'comments' => array ( 0 => array ( 'apptype' => 0, 'attachment' => array ( ), 'channelid' => 974076, 'channeltype' => 1, 'cmtid' => '1016123446', 'content' => '[/发怒][/发怒][/发怒]', 'ctime' => 1462341664000, 'from' => 0, 'ip' => '114.216.94.30', 'opcount' => 0, 'referid' => '1016123446', 'replyid' => '0', 'spcount' => 0, 'user' => array ( 'nickname' => '意琦行', 'sohuPlusId' => 388166532, 'usericon' => '/data/upload/avatar/57298a38b3d63.jpg', 'userid' => '7', 'userurl' => '/user/index/index/id/7.html', ), 'useragent' => 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36', ), ), 'metadata' => '{"local_ip":"10.11.152.42"}', 'title' => '文交所头条-六十周年纪念邮票_文天下', 'ttime' => 1462266235000, 'url' => 'http://www.wen-world.com/article/1276.html', );
			
			dump($data);
			dump($map);
			
		}
	
	
    
	}	
	 

	
	

}

